
<?php
if (!empty($errors)) {
    echo '<div class="alert alert-danger">';
    foreach($errors as $error) {
        echo "<p>$error</p>";
    }
    echo '</div>';
}    
?>

<form class="form-horizontal" action="admin.php?r=articles/update&id=<?php echo $id; ?>" enctype="multipart/form-data" method="post">
    <div class="form-group">
        <label class="control-label col-sm-2">Danh mục</label>
        <div class="col-sm-10">
            <select name="category_id" class="form-control">
                <?php foreach($categories as $category) {
                    $selected = ($category['id'] ==$article['category_id']) ? 'selected=""' : '';
                    echo '<option value="'.$category['id'].'" '.$selected.'>'.$category['name'].'</option>';
                } ?>
            </select>
        </div>        
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Tiêu đề</label>
        <div class="col-sm-10">
            <input name="name" type="text" class="form-control" value="<?php if(isset($article['name'])) echo $article['name']; ?>" placeholder="Tiêu đề"/>
        </div>        
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Keyword</label>
        <div class="col-sm-10">
            <textarea name="keywords" class="form-control" placeholder="SEO Keywords"><?php if(isset($article['keywords'])) echo $article['keywords']; ?></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Description</label>
        <div class="col-sm-10">
            <textarea name="description" class="form-control" placeholder="SEO Description"><?php if(isset($article['description'])) echo $article['description']; ?></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Nội dung</label>
        <div class="col-sm-10">
            <textarea name="content" class="form-control mceEditor" placeholder="Nội dung"><?php if(isset($article['content'])) echo $article['content']; ?></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Ảnh</label>
        <div class="col-sm-10">
            <input name="image" type="file" class="form-control" />
            <?php if(is_file($article['image'])) {
                echo '<img src="'.$article['image'].'" width="200"/>';
            } ?>
        </div>
    </div>
    <div class="form-group">
        <div class="col-lg-10 col-lg-offset-2">
            <input type="submit" class="btn btn-primary" value="Cập nhật" />
            <a  class="btn btn-warning" href="admin.php?r=articles/index">Trở về</a>
        </div>
        
    </div>
</form>

<script type="text/javascript" src="public/plugins/tinymce/tinymce.min.js"></script>